package com.pets.web.controller.admin;


import com.pets.common.annotation.Log;
import com.pets.common.core.controller.BaseController;
import com.pets.common.core.domain.AjaxResult;
import com.pets.common.core.page.TableDataInfo;
import com.pets.common.enums.BusinessType;
import com.pets.common.utils.SecurityUtils;
import com.pets.web.entity.PetsGoods;
import com.pets.web.entity.PetsShop;
import com.pets.web.service.IPetsGoodsService;
import com.pets.web.service.impl.PetsGoodsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author zhurenwang
 * @since 2024-05-25
 */
@RestController
@RequestMapping("/goods")
public class PetsGoodsController extends BaseController {

    @Autowired
    private IPetsGoodsService petsGoodsService;

    @GetMapping("/list")
    public TableDataInfo list(PetsGoods petsGoods){
        startPage();
        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            petsGoods.setSysUserId(SecurityUtils.getUserId());
        }
        List<PetsGoods> list = petsGoodsService.list(petsGoods);
        return getDataTable(list);
    }

    @PostMapping()
    @Log(title = "商品管理", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody PetsGoods petsGoods){
        petsGoods.setSysUserId(SecurityUtils.getUserId());
        return success(petsGoodsService.add(petsGoods));
    }

    @Log
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Integer id){
        return success(petsGoodsService.deleteById(id));
    }

    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable Integer id){
        return success(petsGoodsService.getById(id));
    }

    @Log(title = "商品管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult edit(@RequestBody PetsGoods petsGoods){
        return success(petsGoodsService.updateById(petsGoods));
    }

    @Log(title = "商品管理", businessType = BusinessType.OFFLINE)
    @GetMapping("/offline/{id}")
    public AjaxResult offline(@PathVariable Integer id){
        return success(petsGoodsService.offline(id));
    }

    @Log(title = "商品管理", businessType = BusinessType.ONLINE)
    @GetMapping("/online/{id}")
    public AjaxResult online(@PathVariable Integer id){
        return success(petsGoodsService.online(id));
    }


}
